package com.zhongwang.mms.module.buy.controller;
import com.github.pagehelper.PageHelper;
import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.common.Page;
import com.zhongwang.mms.common.Table;
import com.zhongwang.mms.module.buy.model.PurchaseModel;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.PurchaseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 项目计划看板 控制层
 * @Author: China.kxx
 * @Date: 2020/03/30 10:05
 */
@Slf4j
@Controller
@RequestMapping("/buy/planTraManage")
public class PurchaseController extends BaseController {
    @Autowired
    private PurchaseService purchaseService;
    @GetMapping("index")
    public String planTraManage(Model model){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        String start = sdf.format(new Date());
        String end = sdf2.format(new Date());
        model.addAttribute("start",start+"-1-1");
        model.addAttribute("end",end);
        return "buy/planTraManage/list";
    }
    @PostMapping("listDivision")
    @ResponseBody
    /**
     * 获取设计科室列表
     */
    public JsonResult listDivision(){
        return jsonResult(purchaseService.listDivision());
    }
    /**
     * 项目列表
     * @param purchaseModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"plan:probuydetail:view"})
    public JsonResult list(PurchaseModel purchaseModel) {
        List<PurchaseModel> list = new ArrayList<>();
        try {
            startPage();
            list = purchaseService.findProject(purchaseModel);
        }catch (Exception e){
            e.printStackTrace();
        }
        return jsonResult(list);
    }





    ///**
    // * 项目列表
    // * @param purchaseModel 查询条件
    // * @return list
    // */
    //@ResponseBody
    //@PostMapping("/count")
    //@RequiresPermissions({"plan:probuydetail:view"})
    //public JsonResult count(PurchaseModel purchaseModel) {
    //    Long count = purchaseService.findProjectCount(purchaseModel);
    //    return JsonResult.success("",count);
    //}


}


